package com.hopes.bizz.emergency.job;


import cn.hutool.core.date.DateUtil;
import com.hopes.bizz.common.core.annotation.TenantJobRun;
import com.hopes.bizz.common.core.util.DateUtils;
import com.hopes.bizz.emergency.common.constant.PlanDicConstant;
import com.hopes.bizz.emergency.plan.dto.ErEmergencyPlanDTO;
import com.hopes.bizz.emergency.plan.entity.ErEmergencyPlanEntity;
import com.hopes.bizz.emergency.plan.service.ErEmergencyPlanService;
import com.hopes.bizz.emergency.resources.entity.ErCarEntity;
import com.hopes.bizz.emergency.resources.entity.ErMaterialEntity;
import com.hopes.bizz.emergency.resources.entity.ErTeamEntity;
import com.hopes.bizz.emergency.resources.service.ErCarService;
import com.hopes.bizz.emergency.resources.service.ErMaterialService;
import com.hopes.bizz.emergency.resources.service.ErTeamService;
import com.hopes.bizz.emergency.support.AboutExpireSupport;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @author cx
 * @date 2024/1/10 15:29
 * @description:
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class ExpiresCheckJob {


    private final ErEmergencyPlanService erEmergencyPlanService;
    private final ErMaterialService erMaterialService;
    private final ErTeamService erTeamService;
    private final ErCarService erCarService;

    @TenantJobRun
    @XxlJob("emergencyExpiresCheckJobHandler")
    public void emergencyExpiresCheckJobHandler() {


        // 企业预案
        List<ErEmergencyPlanEntity> erEmergencyPlanEntityList = erEmergencyPlanService.list();
        for (ErEmergencyPlanEntity erEmergencyPlan : erEmergencyPlanEntityList) {
            AboutExpireSupport.setExpireStatus(erEmergencyPlan, ErEmergencyPlanEntity::getDueTime,ErEmergencyPlanEntity::setOverdueStatus);
                // TODO  消息发送 提示
            erEmergencyPlanService.updateById(erEmergencyPlan);
        }

        // 应急物资
        List<ErMaterialEntity> erMaterialEntityList = erMaterialService.list();
        for (ErMaterialEntity erMaterialEntity : erMaterialEntityList) {
            AboutExpireSupport.setExpireStatus(erMaterialEntity, ErMaterialEntity::getDueDate,ErMaterialEntity::setSatus);
            // TODO  消息发送 提示
            erMaterialService.updateById(erMaterialEntity);
        }

        // 应急队伍
        List<ErTeamEntity> erTeamEntityList = erTeamService.list();
        for (ErTeamEntity erTeamEntity : erTeamEntityList) {
            AboutExpireSupport.setExpireStatus(erTeamEntity, ErTeamEntity::getExpiryDate,ErTeamEntity::setOverdueStatus);
            // TODO  消息发送 提示
            erTeamService.updateById(erTeamEntity);
        }

        // 应急车辆
        List<ErCarEntity> erCarEntityList = erCarService.list();
        for (ErCarEntity erCarEntity : erCarEntityList) {
            AboutExpireSupport.setExpireStatus(erCarEntity, ErCarEntity::getScrapTime,ErCarEntity::setOverdueStatus);
            // TODO  消息发送 提示
            erCarService.updateById(erCarEntity);
        }
    }
}
